import { Config } from "@/common/config";
// @ts-ignore

/**
 * 检查是否完整路径.
 * 拼接.
 * @param url
 */
export const checkAndFixUrl = (url: string) :string => {
    // 判断是否包含 "http"
    if (url.length <= 0) {
        return '';
    }
    // @ts-ignore
    if (!url.includes("http")) {
        // 如果不存在，则进行拼接
        url = Config.IME_HOST + '/' + url;
    }

    return url;
}

/**
 * 获取今天后6天的日期数据.
 */
export const getFutureDates = ():Array<any> => {
    const today = new Date();
    const daysOfWeek = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];

    const futureDates = [];

    for (let i = 0; i < 6; i++) {
        const currentDate = new Date(today.getTime() + i * 24 * 60 * 60 * 1000);
        const day = currentDate.getDate();
        const month = currentDate.getMonth() + 1; // Months are zero-based
        const year = currentDate.getFullYear();

        const formattedDate = `${month < 10 ? '0' : ''}${month}/${day < 10 ? '0' : ''}${day}`;
        const dayOfWeek = daysOfWeek[currentDate.getDay()];
        const fullDate = `${year}-${month < 10 ? '0' : ''}${month}-${day < 10 ? '0' : ''}${day}`;

        futureDates.push({
            date: formattedDate,
            desc: i === 0 ? '今天' : i === 1 ? '明天' : dayOfWeek,
            fullDate: fullDate,
        });
    }

    return futureDates;
}
